# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

default_platform(:android)

platform :android do
  desc "Build play bundle"
  lane :build_play_bundle do
    gradle(task: "app:bundlePlayRelease")
  end

  desc "Deploy a new version to the Google Play"
  lane :deploy do |options|
    upload_to_play_store(
      mapping: "app/build/outputs/mapping/playRelease/mapping.txt",
      aab: "app/build/outputs/bundle/playRelease/app-play-release.aab",
      track: options[:track],
      skip_upload_apk: true,
      skip_upload_changelogs: true,
      sync_image_upload: true
    )
  end

  desc "Validate deployment of a new version to the Google Play"
  lane :validate_deploy do |options|
    upload_to_play_store(
      mapping: "app/build/outputs/mapping/playRelease/mapping.txt",
      aab: "app/build/outputs/bundle/playRelease/app-play-release.aab",
      track: options[:track],
      validate_only: true,
      skip_upload_apk: true,
      skip_upload_changelogs: true,
      skip_upload_images: true,
      skip_upload_screenshots: true
    )
  end

  desc "Promotes between tracks"
  lane :promote do |options|
    upload_to_play_store(
      track: options[:track],
      track_promote_to: options[:track_promote_to],
      skip_upload_apk: true,
      skip_upload_aab: true,
      skip_upload_metadata: true,
      skip_upload_changelogs: true,
      skip_upload_images: true,
      skip_upload_screenshots: true
    )
  end

  desc "Build and deploy a new version to the Google Play"
  lane :build_and_deploy do |options|
    # Never change version for releases
    build_play_bundle
    deploy(options)
  end

  desc "Build and validate deployment of a new version to the Google Play"
  lane :build_and_validate do |options|
    build_play_bundle
    validate_deploy(options)
  end
end
